<?php
 class Engine_User_Active extends Engine_User {

    private $__authtorized = false;


    public function __construct() {
        
        if ($auth = Application_Bootstrap::getRequest()->getAuthData()) {
            $this->__authtorized = true;
            $this->data = $auth;
            $userId = $auth['id'];
            $this->permissions = $this->getPermissionsById($userId) ;
        } else {
            $this->__authtorized = false;
        }
    }

    public function checkUserRole() {

     }

     public function isAuthorized() {
        return $this->__authtorized;
     }

     public function checkAuthorize($login, $password) {
        $authorize = false;
        if ($login && $password) {
            $tUser = new Module_Account_Table_User();
            $row = $tUser->getByLogin(trim($login));
            if ($row) {
                if ($row['password'] == sha1($password)) {
                    $authorize = $row;
                }
            }
        }
        return $authorize;
     }

     public function getPermissions() {
        return $this->permissions;
    }

     public function checkPermission($permissionAlias) {
         if (in_array($permissionAlias, $this->permissions)) return true;
         else throw new Exception('Access denied');
     }

 }
